// stdafx.cpp : source file that includes just the standard includes
// APPLoader.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"


BYTE HexTextToBYTE(CString hex)
{
	return tchar_to_value(hex[0]) * 0x10 + tchar_to_value(hex[1]);
}

DWORD HexTextToDWORD(CString hex)
{
	DWORD res = 0;
	for (int i=0;i<8;++i)
	{
		res *= 0x10;
		res += tchar_to_value(hex[i]);
	}
	return res;
}

inline BYTE tchar_to_value(TCHAR c)
{
	switch(c)
	{
	case _T('0'):
		return 0x00;
	case _T('1'):
		return 0x01;
	case _T('2'):
		return 0x02;
	case _T('3'):
		return 0x03;
	case _T('4'):
		return 0x04;
	case _T('5'):
		return 0x05;
	case _T('6'):
		return 0x06;
	case _T('7'):
		return 0x07;
	case _T('8'):
		return 0x08;
	case _T('9'):
		return 0x09;
	case _T('a'):
	case _T('A'):
		return 0x0a;
	case _T('b'):
	case _T('B'):
		return 0x0b;
	case _T('c'):
	case _T('C'):
		return 0x0c;
	case _T('d'):
	case _T('D'):
		return 0x0d;
	case _T('e'):
	case _T('E'):
		return 0x0e;
	case _T('f'):
	case _T('F'):
		return 0x0f;
	default:
		GD_FALSE();
		return 0xff;
	}
}

